package com.community.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.community.dao.IBaseDao;
import com.community.entity.User;
import com.community.service.IUserService;

@Service
public class UserServiceImpl implements IUserService{
	
	@Autowired
	private IBaseDao<User> udao;

	@Override
	public void addUser(User u) {
		// TODO Auto-generated method stub
		udao.save(u);
	}

	@Override
	public void updateUser(User u) {
		// TODO Auto-generated method stub
		udao.update(u);
	}

	@Override
	public void deleteUser(User u) {
		// TODO Auto-generated method stub
		udao.delete(u);
	}

	@Override
	public User getUser(Long id) {
		// TODO Auto-generated method stub
		return udao.get(User.class, id);
	}

	@Override
	public List<User> getUserList() {
		// TODO Auto-generated method stub
		return udao.find("from User");
	}

	@Override
	public User getUserByCountAndPassword(String count, String password) {
		// TODO Auto-generated method stub
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("1", count);
		params.put("2", password);
		
		return udao.get("from User u where u.count = ?1 and u.password = ?2", params);
	}

	@Override
	public User getUserByCount(String count) {
		// TODO Auto-generated method stub
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("1", count);
		
		return udao.get("from User u where u.count = ?1", params);
	}

}
